package cs236369.webserver.examples;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

public class JavaCompile {

	private final JavaCompiler compiler;
	
	public JavaCompile(String compilerPath) {
		String old = System.getProperty("java.home");
		System.setProperty("java.home", compilerPath);
		compiler = ToolProvider.getSystemJavaCompiler();
		if (compiler == null) {
			throw new RuntimeException("no java compiler");
		}
		System.setProperty("java.home", old);
	}
	
	
	public void compile(String srcPath) {
		compiler.run(null, null, null, srcPath);
	}
	
	public static void main(String[] args) throws Exception {
		new JavaCompile("C:\\Program Files\\Java\\jdk1.6.0_24\\").compile("src\\cs236369\\webserver\\examples\\A.java");
		
		Class.forName("cs236369.webserver.examples.A").newInstance();
		
		//Class.forName("A").getConstructor(String.class).newInstance("BB");
		
		
		
	}
}
